<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle" >
        <!-- 搜索 -->
        <el-form label-width="80px" size="small" >
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="被查人">
                <zSelect :value.sync="query.checkedUserIds" :label="query.checkedUserIds" url="api/dropDown/sysUserList"  style="width:  100%;"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6">
              <el-form-item label="业务日期" prop="startDate">
                <div class="flex flex-row">
                  <el-date-picker v-model="query.startCreateDate" type="date" placeholder="开始新增日期" format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd" style="width: 320px" />
                  <el-date-picker v-model="query.endCreateDate" type="date" placeholder="结束新增日期" format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd" style="width: 320px" />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="是否完成" prop="finished">
                <el-select v-model="query.finished" clearable class="edit-input" placeholder="请选择" style="width: 320px" >
                  <el-option v-for="(item, index) in dict.common_yes_or_no" :key="index" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="是否结束" prop="over">
                <el-select v-model="query.over" clearable class="edit-input" placeholder="请选择" style="width: 320px" >
                  <el-option v-for="(item, index) in dict.common_yes_or_no" :key="index" :label="item.label" :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col>

          </el-row>
          <rrOperation :crud="crud" />
        </el-form>

      </div>

      <crudOperation :permission="permission">
        <el-button slot="right" class="filter-item" size="mini" type="danger"  @click="checkwork" :disabled="crud.selections.length < 1" > 查岗 </el-button>
        <el-button
          slot="right"
          :loading="crud.downloadLoading"
          class="filter-item"
          size="mini"
          type="warning"
          @click="doExport"
        >导出</el-button>

      </crudOperation>
    </div>

    <div class="body-container">

      <vue-context-menu :contextMenuData="contextMenuData"
                        @tableConfig="tableConfig"
                        @deletedata="deletedata"></vue-context-menu>
      <!-- 表格配置 -->
      <el-dialog title="表格配置"
                 :visible.sync="tableConfigShow"
                 width="60%">
        <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
      </el-dialog>

      <!--表格渲染-->
      <el-table ref="table" stripe border
                @cell-dblclick="row=>crud.toEdit(row)"
                v-loading="crud.loading"
                :data="crud.data"
                size="small"
                style="width: 100%;"
                v-if="isShowTable"
                @header-dragend="changeColWidth"
                @contextmenu.native="showMenu"
                @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="selection" width="60"/>
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('signInImgUrl')" prop="signInImgUrl" label="签到照片">
          <template slot-scope="scope" >
            <el-image v-if="scope.row.signInImgUrl"
              style="width: 50px; height: 50px"
              :src="scope.row.signInImgUrl" />
              <span v-else>无</span>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('checkedUserName')" prop="checkedUserName" label="被查人名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('checkingUserName')" prop="checkingUserName" label="查岗人名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createTime')" prop="createTime" label="创建时间" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('createUserName')" prop="createUserName" label="创建人名称" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('endTime')" prop="endTime" label="结束时间" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('finished')" prop="finished" label="是否完成" >
          <template slot-scope="scope">
            {{ dict.label.common_yes_or_no[scope.row.finished] }}
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('over')" prop="over" label="是否结束">
          <template slot-scope="scope">
            {{ dict.label.common_yes_or_no[scope.row.over] }}
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('signInLocation')" prop="signInLocation" label="签到地点" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('signInTime')" prop="signInTime" label="签到时间" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('workContent')" prop="workContent" label="工作内容" />

      </el-table>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import {batchCheck} from "@/api/erp/checkWork";
// import jDialog from '@/components/jDialog/jDialog'
import { publicListKey } from "@/utils/key";
import {tablemixins} from "@/mixins/tablemixins";
import { getToken } from '@/utils/auth'
import {download} from "@/api/data";
import {downloadFile} from "@/utils";
// crud交由presenter持有
const defaultCrud = CRUD({
  title: '查岗', url: 'api/checkWork/groupBoxQueryAll',  sort: 'id,asc', crudMethod: {},
  optShow: {
    add: false,
    edit: false,
    del: false,
  },
  props: {
    tableColumns:['checkedUserCode','checkedUserName']
  }
})
const defaultForm = {
  checkedUserCode: "",
  checkedUserId: null,
  checkedUserName:"",
  checkingUserCode:"",
  checkingUserId: null,
  createTime:"",
  checkingUserName: "",
  createUserCode:"",
  createUserId: null,
  createUserName: "",
  endTime: "",
  finished: null,
  id: null,
  over: null,
  reactTime:null,
  signInImgUrl: "",
  signInLat: null,
  signInLng: null,
  signInLocation: "",
  signInTime: "",
  workContent: null,

}
export default {
  name: 'checkWork',
  components: {pagination, crudOperation, rrOperation, udOperation,},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(),publicListKey,tablemixins],
  dicts: ["t_sales_promotion_type", 'common_status', "t_sales_promotion_customer_group_type", "t_bas_customer_is_contact", 'common_yes_or_no', "t_sales_promotion_channel_type",
    "t_sales_promotion_promotion_properties", 'common_order_status', "t_sales_promotion_reach_type", "t_sales_promotion_reach_way",'t_sales_promotion_promotion_orderStatus',
  't_bas_customer_channel_type'],
  data() {
    return {
      headers: { Authorization: getToken() },
      permission: {
        add: ['admin', 'checkWork:add'],
      },
    }
  },
  watch: {},
  created() {

  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    checkwork(){
      batchCheck(this.crud.selections).then(res=>{
        this.$message.success(res.msg)
      })
    },
    doExport(){
      this.crud.downloadLoading = true
      download('/api/checkWork/export', this.crud.getQueryParams(),this.crud.queryType).then(result => {
        downloadFile(result, this.crud.title + '数据', 'xlsx')
        this.crud.downloadLoading = false
      }).catch(() => {
        this.crud.downloadLoading = false
      })
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
  }
}
</script>

<style scoped>
.table-img {
  display: inline-block;
  text-align: center;
  background: #ccc;
  color: #fff;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  vertical-align: middle;
  width: 32px;
  height: 32px;
  line-height: 32px;
}
</style>
